const fs = require("fs");
const archiver = require("archiver");

const output = fs.createWriteStream("dist.zip");
const archive = archiver("zip", {
    zlib: { level: 9 } // 设置压缩级别
});

output.on("close", function () {
    console.log(archive.pointer() + " total bytes");
    console.log("Archiver has been finalized and the output file dist.zip has been created");
});

archive.on("warning", function (err) {
    if (err.code === "ENOENT") {
        console.warn("Stat warning");
    } else {
        throw err;
    }
});

archive.on("error", function (err) {
    throw err;
});

archive.pipe(output);
archive.directory("dist", false);
archive.finalize();
